import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter);

const routes = [
    {
        path: '/',
        redirect: 'index',
        name: '系统首页'
    },
    {
        path: '/',
        name: 'Home',
        component: () => import('../views/home/Home.vue'),
        children: [
            {
                path: '/index',
                name: 'Index',
                meta: {title: '系统首页', key: 'Index', keepAlive: false},
                component: () => import('../views/subpage/index/Index.vue')
            },
            {
                path: '/summary/AreaSummary',
                name: 'AreaSummary',
                meta: {title: '地区数据', key: 'AreaSummary', keepAlive: false},
                component: () => import('../views/summary/AreaSummary.vue'),
            },
            {
                path: '/summary/FinanceSummaryToday',
                name: 'FinanceSummaryToday',
                meta: {title: '今日租售', key: 'FinanceSummaryToday', keepAlive: false},
                component: () => import('../views/summary/FinanceSummaryToday.vue'),
            },
            {
                path: '/summary/FinanceSummaryHistory',
                name: 'FinanceSummaryHistory',
                meta: {title: '历史租售', key: 'FinanceSummaryHistory', keepAlive: false},
                component: () => import('../views/summary/FinanceSummaryHistory.vue'),
            },
            {
                path: '/summary/ClientSummary',
                name: 'ClientSummary',
                meta: {title: '客户统计', key: 'ClientSummary', keepAlive: false},
                component: () => import('../views/summary/ClientSummary.vue'),
            },
            {
                path: '/merchants/Merchant',
                name: 'Merchant',
                meta: {title: '商户管理', key: 'Merchant', keepAlive: false},
                component: () => import('../views/merchants/Merchant.vue'),
            },
            {
                path: '/merchants/WithDraw',
                name: 'WithDraw',
                meta: {title: '商户提现', key: 'WithDraw', keepAlive: false},
                component: () => import('../views/merchants/WithDraw.vue'),
            },
            {
                path: '/merchants/Bills',
                name: 'Bills',
                meta: {title: '商户账单', key: 'Bills', keepAlive: false},
                component: () => import('../views/merchants/Bills.vue'),
            },
            {
                path: '/order/Orders',
                name: 'Orders',
                meta: {title: '订单管理', key: 'Orders', keepAlive: false},
                component: () => import('../views/order/Orders.vue'),
            },
            {
                path: '/order/ReturnApply',
                name: 'ReturnApply',
                meta: {title: '退货申请', key: 'ReturnApply', keepAlive: false},
                component: () => import('../views/order/ReturnApply.vue'),
            },
            {
                path: '/order/ExchangeApply',
                name: 'Orders',
                meta: {title: '换货申请', key: 'ExchangeApply', keepAlive: false},
                component: () => import('../views/order/ExchangeApply.vue'),
            },
            {
                path: '/goods/Category',
                name: 'Category',
                meta: {title: '商品类目', key: 'Category', keepAlive: false},
                component: () => import('../views/goods/Category.vue'),
            },
            {
                path: '/goods/Goods',
                name: 'Goods',
                meta: {title: '商品列表', key: 'Goods', keepAlive: false},
                component: () => import('../views/goods/Goods.vue'),
            },
            /* {
                 path: '/prize/userPrize',
                 name: 'UserPrize',
                 meta: {title: '用户获得奖品', key: 'UserPrize', keepAlive: false},
                 component: () => import('../views/prize/UserPrize.vue'),
             },
             {
                 path: '/admin/adminPasswordChange',
                 name: 'UserPrize',
                 meta: {title: '修改管理员密码', key: 'Admin', keepAlive: false},
                 component: () => import('../views/admin/Admin.vue'),
             }*/
            // {
            //   path: '/log/list',
            //   name: 'log',
            //   meta: { title: '点赞记录',key: 'Log' ,keepAlive:false },
            //   component: () => import('../views/log/Log.vue'),
            // },


        ]
    },
    {
        path: '/login',
        name: 'Login',
        component: () => import('../views/login/Login.vue')
    }

];

// 历史状态，没有#
const router = new VueRouter({
    mode: 'hash',
    base: process.env.BASE_URL,
    routes
});

//注册一个全局前置守卫,确保要调用 next 方法，否则钩子就不会被 resolved
router.beforeEach((to, from, next) => {

    // 获取用户信息
    let userInfo = Vue.ls.get('userInfo', false);

    // 判断用户是否登录
    if (userInfo || to.path === '/login') {
        next();
    } else {
        next({path: '/login'});
    }
});

export default router
